package controllers;

import java.util.List;

import models.Batch;
import models.Brand;
import models.Commodity;
import models.QueryBean;
import models.User;
import play.db.jpa.GenericModel.JPAQuery;
import play.mvc.*;

public class Brands extends Controller {

	public static void index(Long bid){
		
		List<Brand> brands = null;
		if(params.get("_search") != null) {
			brands = Brand.find("byNameLike", "%" + params.get("_search") + "%").fetch();
		} else {
			brands = Brand.find("order by lastModifiedAt, createAt desc").fetch();
		}
		
		//显示某个品牌的商品
		if(bid != null){
			Brand brand = Brand.findById(bid);
			List<Commodity> commodities = Commodity.find("byBrand", brand).fetch();
			renderArgs.put("commodities", commodities);
		}

		render(brands);
	}
	
	public static void show(Long id){
		
	}
}
